var util = require('../../utils/util');
var config = require('../../utils/config');
Page({
  data:{
    userName:'',
    classId:0
  },
  onLoad:function() {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    that.setData({
      userName: userInfo.userName
    })
  },
  nameinput:function(e) {
    this.setData({
      userName: e.detail.value
    })
  },
  classinput(e) {
    this.setData({
      classId: e.detail.value
    })
  },
  submitClass() {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    var options = {
      url: config.clubApi.putClass,
      method: 'PUT',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        userId: userInfo.userId,
        classId: that.data.classId
      }
    };
    util.request(options, (res, err) => {
      if (res.statusCode===200) {
        util.showSuccess('加入成功!', config.showSuccessTime, () => {
          wx.navigateBack();
          wx.navigateBack();
          wx.navigateTo({
            url: '../class/class'
          });
        })
      }
    });
  }
})